#ifdef __cplusplus
extern "C" {
#endif


#include "Form.h"
#include "Application.h"
#include "FormService.h"
#include "__wstr.h"

void __begheader(Form, initialize)
     FormDescriptor * _tFormDescriptor
__begbody
    FormService * formService = __instance(FormService)

	bool isFind = __find(&(formService->mID), Vector__wstr, _tFormDescriptor->mClassName, __wstrequal)
	if(!isFind)
	{
		__begfun(__this(Form), Form, registerClass)
			_tFormDescriptor
		__endfun

		__wstr * wstr = (__wstr *)malloc(sizeof(__wstr));

		__begfun(wstr, __wstr, initialize)
			_tFormDescriptor->mClassName
			__endfun

		__begfun(&(formService->mID), Vector__wstr, pushBack)
		    wstr
		__endfun
	}
    Application * application = __instance(Application)

	__this(Form)->mHandle = ::CreateWindow(
		_tFormDescriptor->mClassName,
		_tFormDescriptor->mCaption,
		WS_OVERLAPPEDWINDOW,
		CW_USEDEFAULT,
		CW_USEDEFAULT,
		CW_USEDEFAULT,
		CW_USEDEFAULT,
		(HWND) NULL,
		(HMENU) NULL,
		application->mHandle,
		(LPVOID) NULL);
__endbody


void __begheader(Form, registerClass)
    FormDescriptor * _tFormDescriptor
__begbody
	Application * application = __instance(Application)
	WNDCLASS wndClass;
	wndClass.style = CS_HREDRAW | CS_VREDRAW;
	wndClass.lpfnWndProc = _tFormDescriptor->mWndProc;
	wndClass.cbClsExtra = 0;
	wndClass.cbWndExtra = 0;
	wndClass.hInstance = application->mHandle;
	wndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
	wndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
	wndClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
	wndClass.lpszMenuName = _tFormDescriptor->mMenuName;
	wndClass.lpszClassName = _tFormDescriptor->mClassName;
	RegisterClass(&wndClass);
__endbody

void __begheader(Form, showGraceful)
    int _tShowCmd
__begbody
    ::ShowWindow(__this(Form)->mHandle, _tShowCmd);
    ::UpdateWindow(__this(Form)->mHandle);
__endbody

void __begheader(Form, addMenu)
	Menu * _tMenu
__begbody
	::SetMenu(__this(Form)->mHandle, _tMenu->mHandle);
__endbody



#ifdef __cplusplus
}
#endif

